package com.biyu.monitormanage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.biyu.monitormanage.common.annotation.SysLog;
import com.biyu.monitormanage.common.feign.AdminFeignService;
import com.biyu.monitormanage.common.utils.PageUtils;
import com.biyu.monitormanage.common.utils.BaseResponse;
import com.biyu.monitormanage.model.dto.RealDataLogDto;
import com.biyu.monitormanage.model.request.RealDataLogRequest;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.biyu.monitormanage.entity.RealTimeDataEntity;
import com.biyu.monitormanage.service.RealTimeDataService;



/**
 * 温湿度日志表
 *
 * @author biyubing
 * @email byb15491665510220@163.com
 * @date 2022-03-12 11:39:22
 */
@RestController
@RequestMapping("monitormanage/temhum")
public class RealTimeDataController {

    private final RealTimeDataService realTimeDataService;
    private final AdminFeignService adminFeignService;

    @Autowired
    public RealTimeDataController(RealTimeDataService realTimeDataService,
                                  AdminFeignService adminFeignService) {
        this.realTimeDataService = realTimeDataService;
        this.adminFeignService = adminFeignService;
    }

    @GetMapping("/list/all")
    @RequiresPermissions("monitormanage:temhum:list")
    public BaseResponse listAll(@RequestParam Map<String, Object> params) {
        PageUtils page = realTimeDataService.queryPageAllOfList(params);
        return BaseResponse.ok().put("page", page);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("monitormanage:temhum:list")
    public BaseResponse list(@RequestParam Map<String, Object> params){
        PageUtils page = realTimeDataService.queryPage(params);

        return BaseResponse.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("monitormanage:temhum:info")
    public BaseResponse info(@PathVariable("id") Long id){
		RealTimeDataEntity temHum = realTimeDataService.getById(id);

        return BaseResponse.ok().put("temHum", temHum);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("monitormanage:temhum:save")
    public BaseResponse save(RealTimeDataEntity realData){

        realTimeDataService.saveAndPolice(realData);

        return BaseResponse.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("monitormanage:temhum:update")
    public BaseResponse update(@RequestBody RealTimeDataEntity temHum){
		realTimeDataService.updateById(temHum);

        return BaseResponse.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("monitormanage:temhum:delete")
    public BaseResponse delete(@RequestBody String[] ids){
		realTimeDataService.removeByIds(Arrays.asList(ids));

        return BaseResponse.ok();
    }

    /**
     * 根据时间查询
     * @param request 请求
     * @return 响应
     */
    @GetMapping("/logForRealData")
    @RequiresPermissions("monitormanage:temhum:logForRealData")
    public BaseResponse queryLogForRealData(RealDataLogRequest request) {
        List<RealDataLogDto> realDataLogDto = realTimeDataService.queryLogForRealData(request);
        return BaseResponse.ok().put("data", realDataLogDto);
    }
}
